package com.ancient.base.exception;

public class _24_ThreadTest implements Runnable {
    @Override
    public void run() {
        int count = 0;
        while (!Thread.currentThread().isInterrupted() && count <= 2000) {
            try {
                System.out.println("count: " + count++ + ";lll："+Thread.currentThread().isInterrupted());
                // 子线程睡眠
                Thread.sleep(1000 * 2);
                System.out.println("方法体：" + Thread.currentThread().isInterrupted());
            } catch (InterruptedException e) {
                System.out.println("异常：" + Thread.currentThread().isInterrupted());
                // 线程中断标志位被重置为false
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) throws Exception {
        _24_ThreadTest threadTest = new _24_ThreadTest();
        Thread thread = new Thread(threadTest);
        thread.start();
        Thread.sleep(1000);
        // 中断线程
        thread.interrupt();
    }
}